package com.hansheng.ssdxs.base;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.hansheng.mvp.view.LifeCircleMvpActivity;
import com.tamsiree.rxkit.RxTool;
import com.tencent.bugly.Bugly;

import butterknife.ButterKnife;

public abstract class BaseActivity extends LifeCircleMvpActivity {

    protected Activity mActivity;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = this;
        ViewInject annotation = this.getClass().getAnnotation(ViewInject.class);
        if (annotation != null) {
            int mainlayoutid = annotation.mainlayoutid();
            if (mainlayoutid > 0) {
                setContentView(mainlayoutid);
                bindView();
                RxTool.init(this);
                //初始化版本更新
                Bugly.init(getApplicationContext(),"6e0e5c3b98",false);
                afterBindView();
            } else {
                throw new RuntimeException("mainlayoutid < 0");
            }
        } else {
            throw new RuntimeException("annotation  = null");
        }
    }

    // 模板方法 设计模式
    public abstract void afterBindView();

    // View 的依赖注入绑定
    private void bindView() {
        ButterKnife.bind(this);
    }
}
